package com.zzyl.nursing.controller.member;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.DeviceDataDayDto;
import com.zzyl.nursing.dto.ElderInfoDto;
import com.zzyl.nursing.dto.HourlyDeviceDataVo;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataVo;
import com.zzyl.nursing.vo.FamilyMemberVo;
import com.zzyl.nursing.vo.FamilyMembers;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody ElderInfoDto elderInfoDto){
        Long userId = UserThreadLocal.getUserId();
        familyMemberService.add(elderInfoDto, userId);

        return AjaxResult.success();
    }
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult selectFamilyMemberList(){
        //获取当前用户id
        Long userId = UserThreadLocal.getUserId();
        List<FamilyMemberVo> familyMemberList = familyMemberService.selectFamilyMemberLists(userId);
        return success(familyMemberList);
    }
    /**
     * 查看家人列表（分页查询）
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public AjaxResult listByPage(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        //获取当前用户id

        Long userId = UserThreadLocal.getUserId();
        List<FamilyMembers> page = familyMemberService.selectFamilyMemberPage(pageNum, pageSize,userId);

        return success(page);
    }
    /**
     * 1.4 查询健康数据
     */
    @GetMapping("queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryHealehData(@PathVariable String iotId){
        List<DeviceDataVo> HealthData = familyMemberService.queryHealehData(iotId);
        return AjaxResult.success(HealthData);

    }
    /**
     * 1.5 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(DeviceDataDayDto deviceDataDayDto) {

        List<HourlyDeviceDataVo> hourlyDeviceDataVoList  = familyMemberService.queryDataByDay(deviceDataDayDto);
        return success(hourlyDeviceDataVoList);
    }
    /**
     * 1.6 按周查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(DeviceDataDayDto deviceDataDayDto) {

        List<HourlyDeviceDataVo> hourlyDeviceDataVoList  = familyMemberService.queryDataByWeek(deviceDataDayDto);
        return success(hourlyDeviceDataVoList);
    }




}
